<% include("../common/header_login.html",{title:"注册"}){} %>
<!-- main start -->
<div class="main_login">
	<div class="header_login">
		<div><a href="${ctxPath}/" class="text-align"><img src="${ctxPath}/static/image/logo_sm.png"></a></div>
		<h4 class="login_title">简单，好用的在线调查系统</h4>
    </div>
	<div class="login_layout">
	 <div class="stage">
	 	<h3 class="text-center">注册</h3>
	 	<form action="${ctxPath}/session/register/add" method="post" id="register_form">
	 	<div class="input-group">
		  <span class="input-group-addon"><span class="glyphicon glyphicon glyphicon-envelope" aria-hidden="true"></span></span>
		  <input type="email" name="email" id="email" class="form-control" placeholder="请输入注册邮箱" >
		</div>
	 	<div class="input-group">
		  <span class="input-group-addon"><span class="glyphicon glyphicon glyphicon-lock" aria-hidden="true"></span></span>
		  <input type="password" name="password" id="password" class="form-control" placeholder="请输入密码" >
		</div>
		<div class="input-group">
		  <span class="input-group-addon"><span class="glyphicon glyphicon glyphicon-lock" aria-hidden="true"></span></span>
		  <input type="password" name="rePassword" id="rePassword" class="form-control" placeholder="请确认密码" >
		</div>
		
		  <button type="button" class="btn btn-success btn-lg btn-block" onclick="check()">注 册</button>
		  
		  <p class="pull-right">已经是我们的小伙伴了 <a href="login">马上登录</a> </p>
	 	</form>
	 </div>
	 
	 	<div class="text-center oauth row">
    		<h5 class="text-center">使用其他公众平台账号登录</h5>
			<div class="icon">
                    <a href="/login/with/sina" class="sina" title="新浪微博"></a>
                    <a href="/login/with/qqzone" class="qqzone" title="QQ"></a>
            </div>
		</div>
	</div>
</div>
<script type="text/javascript">
var email_flg = false;
var pwd_flg = false;
var repwd_flg = false;
$("#email").blur(function(){
    var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
    var email = $(this).val();
    if(!reg.test(email)){
        layer.tips('邮箱格式不正确!', this);
    }else{
        $.post(
				"${ctxPath}/session/check/email",
				{"email":email},
				function(data) {
					if(!data) {
					    layer.msg('该邮箱不可用!', function(){
						      //关闭后的操作
						      });
					    return;
					} 
					layer.tips('该邮箱可用!',"#email");
					email_flg = true;
				}
			);
    }
  });

$("#password").blur(function(){
    var reg = /^[a-zA-Z\w]{5,17}$/;
    var password = $(this).val();
    if(!reg.test(password)){
        layer.tips('密码格式不正确!', this);
    }else{
        pwd_flg = true;
    }
  });
  
$("#rePassword").blur(function(){
    var reg = /^[a-zA-Z\w]{5,17}$/;
    var rePassword = $(this).val();
    var password = $("#password").val();
    if(!reg.test(password)){
        layer.tips('密码格式不正确!', this);
    }else if(password != rePassword){
        layer.tips('两次输入密码不一致!', this);
    }else{
        repwd_flg = true;
    }
  });
  
  function check(){
    var success = pwd_flg && email_flg && repwd_flg;
	if(success){
	    $.post(
				"${ctxPath}/session/register/add",
				$("#register_form").serialize(),
				function(data) {
					if(data=="false") {
					    layer.msg('注册出错，请重新注册', function(){});
					    return;
					} 
					layer.msg('注册成功，即将跳转至登录', {
					    icon: 1
					}, function(){
					    //do something
					    location.href="${ctxPath}/session/login";
					});
				}
			);
	}
  	
  }
</script>
<!-- main end -->
<% include("../common/footer_login.html"){} %>